//
//  SearchViewController.m
//  waiMai
//
//  Created by LONG on 16/4/16.
//  Copyright © 2016年 mac. All rights reserved.
//

#import "SearchViewController.h"

@interface SearchViewController ()

@end

@implementation SearchViewController{
    UISearchBar     *_search;

}
- (UISearchBar *)searchview{
    if (_search == nil) {
        _search = [[UISearchBar alloc]init];
        _search.frame = CGRectMake(5, 55,WIDTH-10, 25);
        _search.placeholder = @" 搜索";
        //_search.delegate = self;
        _search.showsScopeBar = YES;
        [_search setBackgroundImage:[UIImage imageNamed:@"touming"]];
        self.navigationItem.titleView = _search;
    }
    return _search;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    //nav底部线消失
    [self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage = [[UIImage alloc] init];
    
    self.navigationController.navigationBar.translucent = NO;
    [self.navigationController.navigationBar setBarTintColor:UIColorFromRGB(MYColor)];
    
    self.navigationController.interactivePopGestureRecognizer.enabled = YES;
    self.navigationController.interactivePopGestureRecognizer.delegate =(id)self;
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"arrow"] style:UIBarButtonItemStylePlain target:self action:@selector(back)];
    [self.navigationItem.leftBarButtonItem setTintColor:[UIColor whiteColor]];
    self.view.backgroundColor = [UIColor whiteColor];
    // Do any additional setup after loading the view.
    [self searchview];

}
-(BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar{
    _search.showsCancelButton = YES;
    for (UIView *view in [[_search.subviews lastObject] subviews]) {
        if ([view isKindOfClass:[UIButton class]]) {
            UIButton *cancelBtn = (UIButton *)view;
            cancelBtn.titleLabel.font = [UIFont systemFontOfSize:13];
            [cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
            [cancelBtn setTitleColor:UIColorFromRGB(0x333333) forState:UIControlStateNormal];
        }
    }
    return YES;
}
//取消按钮按下时调用
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
    _search.showsCancelButton = NO;
    
    [_search resignFirstResponder];
}
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar{
    
    [_search resignFirstResponder];// 放弃第一响应者
    
}
-(void)back{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:NO];
    
    
    self.tabBarController.tabBar.translucent = YES;
    self.tabBarController.tabBar.hidden = YES;
    
}
@end
